home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / librw / RWTValOrderedVector.z / RWTValOrderedVector
Encoding:
Text File  |  2002-10-03  |  18.3 KB  |  463 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++))))                            RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWTValOrderedVector<T> - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/tvordvec.h>
  13.  
  14.  
  15.  
  16.               RWTValOrderedVector<T> ordvec;
  17.  
  18. PPPPlllleeeeaaaasssseeee NNNNooootttteeee!!!!
  19.      IIIIffff yyyyoooouuuu ddddoooo nnnnooootttt hhhhaaaavvvveeee tttthhhheeee SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ddddeeeessssccccrrrriiiibbbbeeeedddd
  20.      hhhheeeerrrreeee....  OOOOtttthhhheeeerrrrwwwwiiiisssseeee,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ttttoooo RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr described in
  21.      the Class Reference.
  22.  
  23.  
  24. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  25.      RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr<<<<TTTT>>>> is an oooorrrrddddeeeerrrreeeedddd collection.  That is, the items in
  26.      the collection have a meaningful ordered relationship with respect to one
  27.      another and can be accessed by an index number.  The order is set by the
  28.      order of insertion.  Duplicates are allowed.  The class is implemented as
  29.      a vector, allowing efficient insertion and retrieval from the end of the
  30.      collection, but somewhat slower from the beginning of the collection.
  31.      The class TTTT must have:
  32.           well-defined copy semantics (TTTT::::::::TTTT((((ccccoooonnnnsssstttt TTTT&&&&)))) or equivalent);
  33.  
  34.           well-defined assignment semantics (TTTT::::::::ooooppppeeeerrrraaaattttoooorrrr====((((ccccoooonnnnsssstttt TTTT&&&&)))) or
  35.           equivalent);
  36.  
  37.           well-defined equality semantics (TTTT::::::::ooooppppeeeerrrraaaattttoooorrrr========((((ccccoooonnnnsssstttt TTTT&&&&)))));
  38.  
  39.           a default constructor.
  40.  
  41.  
  42. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  43.      Note that an ordered vector has a lllleeeennnnggggtttthhhh (the number of items returned by
  44.      lllleeeennnnggggtttthhhh(((()))) or eeeennnnttttrrrriiiieeeessss(((())))) and a ccccaaaappppaaaacccciiiittttyyyy.  Necessarily, the capacity is
  45.      always greater than or equal to the length.  Although elements beyond the
  46.      collection's length are not used, nevertheless, in a value-based
  47.      collection, they are occupied.  If each instance of class TTTT requires
  48.      considerable resources, then you should ensure that the collection's
  49.      capacity is not much greater than its length, otherwise unnecessary
  50.      resources will be tied up.  Isomorphic
  51.  
  52. EEEExxxxaaaammmmpppplllleeee
  53.               #include <rw/tvordvec.h>
  54.           #include <rw/rstream.h>
  55.           main()  {
  56.             RWTValOrderedVector<double> vec;
  57.             vec.insert(22.0);
  58.             vec.insert(5.3);
  59.             vec.insert(-102.5);
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++))))                            RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.             vec.insert(15.0);
  75.             vec.insert(5.3);
  76.             cout << vec.entries() << " entries0 << endl;  // Prints "5"
  77.             for (int i=0; i<vec.length(); i++)
  78.               cout << vec[i] << endl;
  79.             return 0;
  80.           }
  81.  
  82.  
  83.      Program output:
  84.  
  85.               5 entries
  86.           22
  87.           5.3
  88.           -102.5
  89.           15
  90.           5.3
  91.  
  92. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrr
  93.               RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr<T>(size_t capac=RWDEFAULT_CAPACITY);
  94.  
  95.  
  96.      Create an empty ordered vector with capacity ccccaaaappppaaaacccc.  Should the number of
  97.      items exceed this value, the vector will be resized automatically.
  98.  
  99.               RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr<T>(const RWTValOrderedVector<T>& c);
  100.  
  101.  
  102.      Constructs a new ordered vector as a copy of cccc.  The copy constructor of
  103.      all elements in the vector will be called.  The new vector will have the
  104.      same capacity and number of members as the old vector.
  105.  
  106. PPPPuuuubbbblllliiiicccc OOOOppppeeeerrrraaaattttoooorrrrssss
  107.               RWTValOrderedVector<T>&
  108.           ooooppppeeeerrrraaaattttoooorrrr====(const RWTValOrderedVector& c);
  109.  
  110.  
  111.      Sets self to a copy of cccc.  The copy constructor of all elements in the
  112.      vector will be called.  Self will have the same capacity and number of
  113.      members as the old vector.
  114.  
  115.               T&
  116.           ooooppppeeeerrrraaaattttoooorrrr(((())))(size_t i);
  117.           const T&
  118.           ooooppppeeeerrrraaaattttoooorrrr(((())))(size_t i) const;
  119.  
  120.  
  121.      Returns the iiiith value in the vector.  The first variant can be used as an
  122.      llllvvvvaaaalllluuuueeee, the second cannot.  The index iiii must be between zero and the
  123.      number of items in the collection less one.  No bounds checking is
  124.      performed.
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++))))                            RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.               T&
  141.           ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i);
  142.           const T&
  143.           ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i) const;
  144.  
  145.  
  146.      Returns the iiiith value in the vector.  The first variant can be used as an
  147.      llllvvvvaaaalllluuuueeee, the second cannot.  The index iiii must be between zero and the
  148.      number of items in the collection less one, or an exception of type
  149.      RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown.
  150.  
  151. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  152.               void
  153.           aaaappppppppeeeennnndddd(const T& a);
  154.  
  155.  
  156.      Appends the value aaaa to the end of the vector.  The collection will
  157.      automatically be resized if this causes the number of items in the
  158.      collection to exceed the capacity.
  159.  
  160.               T&
  161.           aaaatttt(size_t i);
  162.           const T&
  163.           aaaatttt(size_t i) const;
  164.  
  165.  
  166.      Return the iiiith value in the vector.  The first variant can be used as an
  167.      llllvvvvaaaalllluuuueeee, the second cannot.  The index iiii must be between 0 and the length
  168.      of the vector less one or an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be
  169.      thrown.
  170.  
  171.               void
  172.           cccclllleeeeaaaarrrr();
  173.  
  174.  
  175.      Removes all items from the collection.
  176.  
  177.               RWBoolean
  178.           ccccoooonnnnttttaaaaiiiinnnnssss(const T& a) const;
  179.  
  180.  
  181.      Returns TTTTRRRRUUUUEEEE if the collection contains an item that is equal to aaaa.  A
  182.      linear search is done.  Equality is measured by the class-defined
  183.      equality operator.
  184.  
  185.               const T*
  186.           ddddaaaattttaaaa() const;
  187.  
  188.  
  189.      Returns a pointer to the raw data of the vector.  The contents should not
  190.      be changed.  Should be used with care.
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++))))                            RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.               size_t
  207.           eeeennnnttttrrrriiiieeeessss() const;
  208.  
  209.  
  210.      Returns the number of items currently in the collection.
  211.  
  212.               RWBoolean
  213.           ffffiiiinnnndddd(const T& target, T& ret) const;
  214.  
  215.  
  216.      Performs a linear search and returns TTTTRRRRUUUUEEEE if the vector contains an
  217.      object that is equal to the object ttttaaaarrrrggggeeeetttt and puts a copy of the matching
  218.      object into rrrreeeetttt.  Returns FFFFAAAALLLLSSSSEEEE otherwise and does not touch rrrreeeetttt.
  219.      Equality is measured by the class-defined equality operator.
  220.  
  221.               T&
  222.           ffffiiiirrrrsssstttt();
  223.           const T&
  224.           ffffiiiirrrrsssstttt() const;
  225.  
  226.  
  227.      Returns the first item in the collection.  An exception of type
  228.      RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will occur if the vector is empty.
  229.  
  230.               size_t
  231.           iiiinnnnddddeeeexxxx(const T& a) const;
  232.  
  233.  
  234.      Performs a linear search, returning the index of the first item that is
  235.      equal to aaaa.  Returns RRRRWWWW____NNNNPPPPOOOOSSSS if there is no such item.  Equality is
  236.      measured by the class-defined equality operator.
  237.  
  238.               void
  239.           iiiinnnnsssseeeerrrrtttt(const T& a);
  240.  
  241.  
  242.      Appends the value aaaa to the end of the vector.  The collection will
  243.      automatically be resized if this causes the number of items in the
  244.      collection to exceed the capacity.
  245.  
  246.               void
  247.           iiiinnnnsssseeeerrrrttttAAAAtttt(size_t i, const T& a);
  248.  
  249.  
  250.      Inserts the value aaaa into the vector at index iiii.  The item previously at
  251.      position iiii is moved to iiii++++1111, eeeettttcccc.  The collection will automatically be
  252.      resized if this causes the number of items in the collection to exceed
  253.      the capacity.  The index iiii must be between 0 and the number of items in
  254.      the vector or an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will occur.
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++))))                            RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++))))
  269.  
  270.  
  271.  
  272.               RWBoolean
  273.           iiiissssEEEEmmmmppppttttyyyy() const;
  274.  
  275.  
  276.      Returns TTTTRRRRUUUUEEEE if there are no items in the collection, FFFFAAAALLLLSSSSEEEE otherwise.
  277.  
  278.               T&
  279.           llllaaaasssstttt();
  280.           const T&
  281.           llllaaaasssstttt() const;
  282.  
  283.  
  284.      Returns the last item in the collection.  If there are no items in the
  285.      collection then an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will occur.
  286.  
  287.               size_t
  288.           lllleeeennnnggggtttthhhh() const;
  289.  
  290.  
  291.      Returns the number of items currently in the collection.
  292.  
  293.               size_t
  294.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const T& a) const;
  295.  
  296.  
  297.      Performs a linear search, returning the number of items that are equal to
  298.      aaaa.  Equality is measured by the class-defined equality operator.
  299.  
  300.               void
  301.           pppprrrreeeeppppeeeennnndddd(const T& a);
  302.  
  303.  
  304.      Prepends the value aaaa to the beginning of the vector.  The collection will
  305.      automatically be resized if this causes the number of items in the
  306.      collection to exceed the capacity.
  307.  
  308.               RWBoolean
  309.           rrrreeeemmmmoooovvvveeee(const T& a);
  310.  
  311.  
  312.      Performs a linear search, removing the first object which is equal to the
  313.      object aaaa and returns TTTTRRRRUUUUEEEE.  Returns FFFFAAAALLLLSSSSEEEE if there is no such object.
  314.      Equality is measured by the class-defined equality operator.
  315.  
  316.               size_t
  317.           rrrreeeemmmmoooovvvveeeeAAAAllllllll(const T& a);
  318.  
  319.  
  320.      Removes all items which are equal to aaaa, returning the number removed.
  321.      Equality is measured by the class-defined equality operator.
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++))))                            RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++))))
  335.  
  336.  
  337.  
  338.               T
  339.           rrrreeeemmmmoooovvvveeeeAAAAtttt(size_t i);
  340.  
  341.  
  342.      Removes and returns the object at index iiii.  An exception of type
  343.      RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown if iiii is not a valid index.  Valid indices
  344.      are from zero to the number of items in the list less one.
  345.  
  346.               T
  347.           rrrreeeemmmmoooovvvveeeeFFFFiiiirrrrsssstttt();
  348.  
  349.  
  350.      Removes and returns the first object in the collection.  An exception of
  351.      type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown if the list is empty.
  352.  
  353.               T
  354.           rrrreeeemmmmoooovvvveeeeLLLLaaaasssstttt();
  355.  
  356.  
  357.      Removes and returns the last object in the collection.  An exception of
  358.      type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown if the list is empty.
  359.  
  360.               void
  361.           rrrreeeessssiiiizzzzeeee(size_t N);
  362.  
  363.  
  364.      Changes the capacity of the collection to NNNN.  Note that the number of
  365.      objects in the collection does not change, just the capacity.
  366.  
  367. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss
  368.               RWvostream&
  369.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm,
  370.                  const RWTValOrderedVector<T>& coll);
  371.           RWFile&
  372.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTValOrderedVector<T>& coll);
  373.  
  374.  
  375.      Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to
  376.      it if it has already been saved.
  377.  
  378.               RWvistream&
  379.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTValOrderedVector<T>& coll);
  380.           RWFile&
  381.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTValOrderedVector<T>& coll);
  382.  
  383.  
  384.      Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm.
  385.  
  386.               RWvistream&
  387.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTValOrderedVector<T>*& p);
  388.           RWFile&
  389.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTValOrderedVector<T>*& p);
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++))))                            RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++))))
  401.  
  402.  
  403.  
  404.      Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a
  405.      new collection off the heap and sets pppp to point to it, or sets pppp to point
  406.      to a previously read instance.  If a collection is created off the heap,
  407.      then you are responsible for deleting it.
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.